package com.wc.alorithm_blue_bridge.线段树.算法工程师;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/9/21 20:15
 * @description https://www.lanqiao.cn/problems/19853/learning/?contest_id=207
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static long INF = (long) 1e12;
    static int[] a = new int[N];
    /**
     * 思维：买前i 个药所花的最少的前， 需要找到 [l - 1, i] 区间内最小值, 用到线段树
     */

    static long[] f = new long[N];
    static long[] min = new long[N << 2];
    static HashMap<Integer, ArrayList<Integer>> map = new HashMap<>();
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        // 初始化
        for (int i = 1; i <= m; i++) {
            int l = sc.nextInt(), r = sc.nextInt(), c = sc.nextInt();
            ArrayList<Integer> a1;
            if (map.containsKey(r)) {
                a1 = map.get(r);
            } else {
                a1 = new ArrayList<>();
                map.put(r, a1);
            }
            a1.add(l);
            a1.add(c);
        }
        for (int i = 1; i <= n; i++) f[i] = f[i - 1] + a[i];
        build(1, 1, n);
        for (int i = 1; i <= n; i++) {
            if (map.containsKey(i)) {
                ArrayList<Integer> a1 = map.get(i);
                int len = a1.size();
                for (int j = 0; j < len; j += 2) {
                    int l = a1.get(j), c = a1.get(j + 1);
                    if (l - 1 == 0) {
                        f[i] = Math.min(c, f[i]);
                        f[i] = Math.min(getMin(1, 1, n, l, i) + c, f[i]);
                    }else f[i] = Math.min(getMin(1, 1, n, l - 1, i) + c, f[i]);
                }
            }
            f[i] = Math.min(f[i - 1] + a[i], f[i]);
            modify(1, 1, n, i);
        }


        out.println(f[n]);
        out.flush();
    }

    static void build(int u, int l, int r) {
        if (l == r) {
            min[u] = f[l];
            return;
        }
        int mid = l + r >> 1;
        build(u << 1, l, mid);
        build(u << 1 | 1, mid + 1, r);
        min[u] = Math.min(min[u << 1], min[u << 1 | 1]);
    }

    static void modify(int u, int l, int r, int p) {
        if (l == r) {
            min[u] = f[p];
            return;
        }
        int mid = l + r >> 1;
        if (p <= mid) modify(u << 1, l, mid, p);
        else modify(u << 1 | 1, mid + 1, r, p);
        min[u] = Math.min(min[u << 1], min[u << 1 | 1]);
    }

    static long getMin(int u, int l, int r, int ql, int qr) {
        if (l == ql && r == qr) {
            return min[u];
        }
        int mid = l + r >> 1;
        if (qr <= mid) return getMin(u << 1, l, mid, ql, qr);
        else if (ql > mid) return getMin(u << 1 | 1, mid + 1, r, ql, qr);
        long left = getMin(u << 1, l, mid, ql, mid);
        long right = getMin(u << 1 | 1, mid + 1, r, mid + 1, qr);
        return Math.min(left, right);
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
